package gui;

import classes.Ausencia;
import classes.Gozo;
import classes.Servidor;
import controlador.LoginControlador;
import erro.ConexaoException;
import erro.ConsultaException;
import erro.GeralException;
import fachada.Fachada;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.mail.internet.AddressException;
import javax.swing.JOptionPane;
import org.apache.commons.mail.EmailException;
import rn.Email;

/**
 *
 * @author roberta.m.carvalho
 */
public class GozoExibir extends javax.swing.JFrame {

    Gozo gozo = new Gozo();
    Gozo g = new Gozo();
    Servidor s = new Servidor();
    ArrayList<Ausencia> listaAus = new ArrayList<Ausencia>();
    Fachada fachada = new Fachada();

    /** Creates new form AusenciaExibir */
    public GozoExibir() {
        initComponents();
        this.setIconImage(Login.icone.getImage());
        dateInicial.setEnabled(false);
        dateFinal.setEnabled(false);
        panelStatus.setVisible(false);
        btSalvar.setVisible(false);
        this.setLocationRelativeTo(null);

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        grupoStatus = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        dateInicial = new com.toedter.calendar.JDateChooser();
        dateFinal = new com.toedter.calendar.JDateChooser();
        textDias = new javax.swing.JTextField();
        lbSaldo = new javax.swing.JLabel();
        lbStatus = new javax.swing.JLabel();
        panelStatus = new javax.swing.JPanel();
        rdAprovado = new javax.swing.JRadioButton();
        rdRecusado = new javax.swing.JRadioButton();
        lbAquisitivo = new javax.swing.JLabel();
        btCalcular = new javax.swing.JButton();
        btAlterar = new javax.swing.JButton();
        btExcluir = new javax.swing.JButton();
        btSalvar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Gozo");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("Período aquisitivo:");

        jLabel2.setText("Data Inicial:");

        jLabel3.setText("Data Final:");

        jLabel4.setText("Qtde Dias:");

        jLabel5.setText("Saldo:");

        jLabel6.setText("Status:");

        dateInicial.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                dateInicialPropertyChange(evt);
            }
        });

        dateFinal.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                dateFinalPropertyChange(evt);
            }
        });

        textDias.setEditable(false);

        panelStatus.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        grupoStatus.add(rdAprovado);
        rdAprovado.setText("Aprovado");

        grupoStatus.add(rdRecusado);
        rdRecusado.setText("Recusado");

        javax.swing.GroupLayout panelStatusLayout = new javax.swing.GroupLayout(panelStatus);
        panelStatus.setLayout(panelStatusLayout);
        panelStatusLayout.setHorizontalGroup(
            panelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelStatusLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(rdAprovado)
                .addGap(18, 18, 18)
                .addComponent(rdRecusado)
                .addContainerGap(162, Short.MAX_VALUE))
        );
        panelStatusLayout.setVerticalGroup(
            panelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelStatusLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rdAprovado)
                    .addComponent(rdRecusado))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btCalcular.setText("Calcular");
        btCalcular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCalcularActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbAquisitivo)
                            .addComponent(dateInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(dateFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btCalcular))
                            .addComponent(textDias, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbSaldo)
                            .addComponent(lbStatus)))
                    .addComponent(panelStatus, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lbAquisitivo))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(dateInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3)
                            .addComponent(dateFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(textDias, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(lbSaldo))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(lbStatus)))
                    .addComponent(btCalcular))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/editar.png"))); // NOI18N
        btAlterar.setText("Alterar");
        btAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAlterarActionPerformed(evt);
            }
        });

        btExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/excluir.png"))); // NOI18N
        btExcluir.setText("Excluir");
        btExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExcluirActionPerformed(evt);
            }
        });

        btSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/salvar.png"))); // NOI18N
        btSalvar.setText("Salvar");
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(btSalvar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btExcluir, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btAlterar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btAlterar)
                        .addGap(18, 18, 18)
                        .addComponent(btExcluir)
                        .addGap(18, 18, 18)
                        .addComponent(btSalvar)))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAlterarActionPerformed
        Servidor s = new Servidor();
        try {
            if (g.getAberto() == 2) {
                JOptionPane.showMessageDialog(null, "Após encerrado não é possível alterar o gozo!");
                btSalvar.setEnabled(false);
                this.repaint();
            } else {
                s.setLogin(LoginControlador.login);
                s = fachada.pesquisarLogin(s);
                btSalvar.setVisible(true);
                if (LoginControlador.nivel == 1) {
                    panelStatus.setVisible(true);
                    dateInicial.setEnabled(true);
                    dateFinal.setEnabled(true);
                    if (lbStatus.getText().equals("Aprovado")) {
                        rdAprovado.setSelected(true);
                    } else if (lbStatus.getText().equals("Em análise")) {
                        grupoStatus.clearSelection();
                    } else if (lbStatus.getText().equals("Recusado")) {
                        rdRecusado.setSelected(true);
                    }
                }
                if (LoginControlador.nivel == 2 || LoginControlador.nivel == 3) {
                    btExcluir.setVisible(false);
                    panelStatus.setVisible(false);
                    dateInicial.setEnabled(true);
                    dateFinal.setEnabled(true);
                }
            }
        } catch (ConexaoException ex) {
            JOptionPane.showMessageDialog(null, "Não foi possível conectar-se ao banco de dados!\n" + ex);
        } catch (ConsultaException ex) {
            JOptionPane.showMessageDialog(null, "Ocorreu um erro!\n" + ex);
        }
    }//GEN-LAST:event_btAlterarActionPerformed

    private void btExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExcluirActionPerformed
        if (g.getAberto() == 2) {
            JOptionPane.showMessageDialog(null, "Após encerrado não é possível excluir o gozo!");
            this.repaint();
        } else {
            int selectedOption = JOptionPane.showConfirmDialog(null, "Deseja realmente excluir o evento?", "Alerta!", JOptionPane.YES_NO_OPTION);
            if (selectedOption == JOptionPane.YES_OPTION) {

                try {
                    Gozo gozo = new Gozo();
                    Ausencia a = new Ausencia();
                    a.setSaldo(Integer.parseInt(lbSaldo.getText()));
                    a.setCod(g.getAusencia().getCod());
                    gozo.setCod(g.getCod());
                    fachada.deletarGozo(gozo);
                    fachada.alterarSaldo(a);
                    JOptionPane.showMessageDialog(null, "Excluído com sucesso!");
                    TarefaListarTela tlt = new TarefaListarTela();
                    tlt.carregarTbAusencia();
                    this.dispose();

                } catch (GeralException ex) {
                    JOptionPane.showMessageDialog(null, "Ocorreu um erro!\n" + ex);
                } catch (ConexaoException ex) {
                    JOptionPane.showMessageDialog(null, "Não foi possível conectar-se ao banco de dados!\n" + ex);
                } catch (ConsultaException ex) {
                    JOptionPane.showMessageDialog(null, "Ocorreu um erro!\n" + ex);
                }

            } else {
                this.repaint();
            }
        }
    }//GEN-LAST:event_btExcluirActionPerformed

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        try {
            Fachada f = new Fachada();
            Ausencia ausencia = new Ausencia();
            gozo.setDataInicial(dateInicial.getDate());
            gozo.setDataFinal(dateFinal.getDate());
            ausencia.setCod(g.getAusencia().getCod());
            f.pesquisarAusencia(ausencia);
            long dias = calcularDias(gozo.getDataInicial(), gozo.getDataFinal());                     
            ausencia.setSaldo(Integer.parseInt(lbSaldo.getText()));
            gozo.setAusencia(ausencia);
            gozo.setCod(g.getCod());
            gozo.setAberto(1);
            gozo.setStatus(1);
            gozo.setDias(dias);
            if (rdAprovado.isSelected() == true) {
                gozo.setStatus(2);
            } else if (rdRecusado.isSelected() == true) {
                ArrayList<String> nome = new ArrayList<String>();
                gozo.setStatus(3);
                String assunto, conteudo, anexo = "", arquivo = "";
                Servidor serv = new Servidor();
                serv.setEmailProf(g.getServidor().getEmailProf());
                assunto = "Por favor altere o seu período de Gozo.";
                conteudo = "Foi recusado o período de gozo que você cadastrou.";
                nome.add(serv.getEmailProf().toString());
                Email e = new Email();
                e.enviaEmail(nome, assunto, conteudo, anexo, arquivo);
                JOptionPane.showMessageDialog(null, "O e-mail já foi enviado ao servidor: " + g.getServidor().getNome() + "!");
            }
            fachada.alterarGozo(gozo);
            fachada.alterarSaldo(ausencia);
            JOptionPane.showMessageDialog(null, "Alterado com sucesso!");
            TarefaListarTela tlt = new TarefaListarTela();
            tlt.carregarTbAusencia();
            this.dispose();

        } catch (EmailException ex) {
            JOptionPane.showMessageDialog(null, "Não foi possível enviar o email!\n" + ex);
        } catch (ConexaoException e) {
            JOptionPane.showMessageDialog(null, "Não foi possível conectar-se ao banco de dados!\n" + e);
        } catch (ConsultaException e) {
            JOptionPane.showMessageDialog(null, "Não foi possível inserir!\n" + e);
        } catch (GeralException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
            this.repaint();
        } catch (AddressException ex) {
            //
        }

    }//GEN-LAST:event_btSalvarActionPerformed

    private void dateFinalPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dateFinalPropertyChange
        if (evt.getPropertyName().equals("date")) {
            Date dataInicio = dateInicial.getDate();

            Date dataFinal = dateFinal.getDate();

            long diferenca = dataFinal.getTime()
                    - dataInicio.getTime();

            int tempoDia = 1000 * 60 * 60 * 24;

            long diasDiferenca = (diferenca / tempoDia) + 1;
            long dias = g.getDias();
            long soma = dias + g.getAusencia().getSaldo();

            if (diasDiferenca > soma) {
                JOptionPane.showMessageDialog(rootPane, "Quantidade de dias (" + diasDiferenca + ") maior que o saldo!\n O seu saldo atual é: " + soma);
                dateInicial.setDate(g.getDataInicial());
                dateFinal.setDate(g.getDataFinal());
            } else {
                textDias.setText(String.valueOf(diasDiferenca));
                int sub = (int) (soma - diasDiferenca);
                lbSaldo.setText(String.valueOf(sub));
                btSalvar.setEnabled(true);
            }
        }
    }//GEN-LAST:event_dateFinalPropertyChange

    private void dateInicialPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dateInicialPropertyChange
        if (evt.getPropertyName().equals("date")) {
            dateFinal.setMinSelectableDate(dateInicial.getDate());
            //  dateFinalPropertyChange(null);
        }
    }//GEN-LAST:event_dateInicialPropertyChange

    private void btCalcularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCalcularActionPerformed
        // TODO add your handling code here:
        Date dataInicio = dateInicial.getDate();

        Date dataFinal = dateFinal.getDate();

        long diferenca = calcularDias(dataInicio, dataFinal);

        if (Integer.parseInt(lbSaldo.getText()) == 0 && diferenca > g.getDias()) {
                JOptionPane.showMessageDialog(rootPane, "Quantidade de dias maior que o saldo!");
                btSalvar.setEnabled(false);           
        } else {
            textDias.setText(String.valueOf(diferenca));
            long saldo = g.getDias() - diferenca ;
            lbSaldo.setText(String.valueOf(saldo));
            btSalvar.setEnabled(true);
        }
    }//GEN-LAST:event_btCalcularActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GozoExibir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GozoExibir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GozoExibir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GozoExibir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new GozoExibir().setVisible(true);
            }
        });
    }

    public final void carregarCombo() {

        Servidor servidor = new Servidor();
        servidor.setMatricula(s.getMatricula());
        try {
            Ausencia a = new Ausencia();
            Gozo gozo = new Gozo();
            gozo.setCod(Gozo.idGozo);
            a = fachada.PesquisarPeriodo(gozo);

            DateFormat formatdata = new SimpleDateFormat("MM-yyyy");
            Date dataIni = a.getAquisitivoInicial();
            String dataI = (formatdata.format(dataIni));
            Date dataFim = a.getAquisitivoFinal();
            String dataF = (formatdata.format(dataFim));
            lbAquisitivo.setText(a.getTipo().getNome() + ": " + dataI + " - " + dataF);
            // combo = a.getTipo().getNome() + ": " + dataI + " - " + dataF;
            //cbPeriodos.addItem(combo);

        } catch (ConexaoException ex) {
            JOptionPane.showMessageDialog(null, "Não foi possível conectar-se ao banco de dados!\n" + ex);
        } catch (ConsultaException ex) {
            JOptionPane.showMessageDialog(null, "Ocorreu um erro ao tentar carregar a tela.\n" + ex);
        }
    }

    public void carregarTela() {
        g.setCod(Gozo.idGozo);
        Servidor serv = new Servidor();
        try {
            serv.setLogin(LoginControlador.login);
            if (LoginControlador.nivel == 3) {
                btExcluir.setVisible(false);
            }
            g = fachada.pesquisarGozo(g);
            s.setMatricula(g.getServidor().getMatricula());
            carregarCombo();
            String sd = String.valueOf(g.getAusencia().getSaldo());
            lbSaldo.setText(sd);
            textDias.setText(String.valueOf(g.getDias()));
            dateInicial.setDate(g.getDataInicial());
            dateFinal.setDate(g.getDataFinal());
            int status = g.getStatus();
            if (status == 1) {
                lbStatus.setText("Em análise");
            } else if (status == 2) {
                lbStatus.setText("Aprovado");
            }

        } catch (ConexaoException ex) {
            JOptionPane.showMessageDialog(null, "Não foi possível conectar-se ao banco de dados!\n" + ex);
        } catch (ConsultaException ex) {
            JOptionPane.showMessageDialog(null, "Ocorreu um erro ao tentar carregar a tela.\n" + ex);
        }
    }

    public static long calcularDias(Date dataInicio, Date dataFinal) {

        long diferenca = (dataFinal.getTime()
                - dataInicio.getTime());

        int tempoDia = 1000 * 60 * 60 * 24;

        long diasDiferenca = (diferenca / tempoDia) + 1;

        return diasDiferenca;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton btAlterar;
    private javax.swing.JButton btCalcular;
    public javax.swing.JButton btExcluir;
    private javax.swing.JButton btSalvar;
    private com.toedter.calendar.JDateChooser dateFinal;
    private com.toedter.calendar.JDateChooser dateInicial;
    private javax.swing.ButtonGroup grupoStatus;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lbAquisitivo;
    private javax.swing.JLabel lbSaldo;
    private javax.swing.JLabel lbStatus;
    private javax.swing.JPanel panelStatus;
    private javax.swing.JRadioButton rdAprovado;
    private javax.swing.JRadioButton rdRecusado;
    private javax.swing.JTextField textDias;
    // End of variables declaration//GEN-END:variables
}
